package book;

/**
 * 和书相关
 */

public class Book {
    //一本书的属性
    private String name; //书名
    private String author; //作者
    private double price; //价格
    private String type; //类型
    private boolean isBorrowed; //是否被借出

    //提供构造方法，方便实例化
    public Book(String name, String author, double price, String type) {
        this.name = name;
        this.author = author;
        this.price = price;
        this.type = type;
        //不实例化isBorrowed原因：boolean默认值为false，未被借出
    }

    //书的属性被private修饰，提供get和set方法，方便在类外使用
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getAuthor() {
        return author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }
    public double getPrice() {
        return price;
    }
    public void setPrice(int price) {
        this.price = price;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public boolean isBorrowed() {
        return isBorrowed;
    }
    public void setBorrowed(boolean borrowed) {
        isBorrowed = borrowed;
    }

    @Override
    public String toString() {
        return "Book{" +
                "name='" + name + '\'' +
                ", author='" + author + '\'' +
                ", price=" + price +
                ", type='" + type + '\'' +
                ((isBorrowed == true) ? ", 已被借出" : ", 未被借出") +
//                ", isBorrowed=" + isBorrowed +
                '}';
    }
}
